/**
 * @开发版权 zhous
 * @项目名称 micro
 * @版本信息 v1.0
 * @开发人员 zhous
 * @开发日期 2025-05-23
 * @修订日期
 * @描述  Knife4jConfig
 */
package com.microframework.base.core.swagger.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class Knife4jConfig{

	@Value("${knife4j.openapi.title:API文档}")
	private String title;

	@Value("${knife4j.openapi.description:API文档说明}")
	private String description;

	@Value("${knife4j.openapi.version:1.0.0}")
	private String version;

	@Value("${knife4j.openapi.license:Apache 2.0}")
	private String licenseName;

	@Value("${knife4j.openapi.license-url:https://www.apache.org/licenses/LICENSE-2.0}")
	private String licenseUrl;

	@Value("${knife4j.openapi.contact.name:开发团队}")
	private String contactName;

	@Value("${knife4j.openapi.contact.email:dev@example.com}")
	private String contactEmail;

	@Value("${knife4j.openapi.contact.url:https://example.com}")
	private String contactUrl;

	@Bean
	public OpenAPI customOpenAPI() {
		return new OpenAPI()
				// 从配置文件中读取API标题、描述与版本
				.info(new Info().title(title).description(description).version(version)
						// 从配置文件中读取开发者联系信息
						.contact(new Contact().name(contactName).email(contactEmail).url(contactUrl))
						// 从配置文件中读取许可证信息
						.license(new License().name(licenseName).url(licenseUrl)));
	}
	
	@Bean
	public GroupedOpenApi authManangeOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("认证管理")
	            .pathsToMatch("/auth/**")
	            .build();
	}
	
	@Bean
	public GroupedOpenApi systemManangeOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("系统管理")
	            .pathsToMatch("/sys/**")
	            .build();
	}
	
	@Bean
	public GroupedOpenApi dataRuleManangeOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("数据规则管理")
	            .pathsToMatch("/data-rule/**")
	            .build();
	}
	
	@Bean
	public GroupedOpenApi customApiManangeOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("自定义接口管理")
	            .pathsToMatch("/custom-api/**")
	            .build();
	}
	
	@Bean
	public GroupedOpenApi customVisualManangeOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("可视化设计器接口管理")
	            .pathsToMatch("/visual/**")
	            .build();
	}
	
	@Bean
	public GroupedOpenApi customDataCollectOpenAPI() {
	    return GroupedOpenApi.builder()
	            .group("数据采集接口管理")
	            .pathsToMatch("/data-collect/**")
	            .build();
	}

}
